package com.example.dbcms.controller.admin;

import com.example.dbcms.annotation.Log;
import com.example.dbcms.domain.ParkingFeeInfo;
import com.example.dbcms.service.ParkingFeeService;
import com.example.dbcms.utils.ResultVoUtil;
import com.example.dbcms.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/admin/parkingFee")
@Api("停车费用操作")
public class ParkingFeeController {

    @Autowired
    private ParkingFeeService parkingFeeService;

    /**
     * 查询停车费用记录
     * @param modelMap
     * @return
     */
    @ApiOperation("查询停车费用记录")
    @GetMapping("/parkingPayInfo")
    @Log(type="查询停车费用记录")
    public String parkingPayInfo(ParkingFeeInfo parkingFeeInfo, ModelMap modelMap) {
        PageInfo<ParkingFeeInfo> parkingFeeInfoPageInfo = parkingFeeService.selectAllParkingFeeInfo(parkingFeeInfo);
        modelMap.put("parkingFeeInfoList", parkingFeeInfoPageInfo.getList());
        modelMap.put("parkingFeeInfo", parkingFeeInfo);
        modelMap.put("pageInfo",parkingFeeInfoPageInfo);
        return "admin/parkingFee/index";
    }

    /**
     * 跳转到新增停车费用记录页面
     * @return
     */
    @GetMapping("/addParkingFee")
    @ApiOperation("跳转到新增停车费用记录页面")
    @Log(type="跳转到新增停车费用记录页面")
    public String addParkingFee(){
        return "admin/parkingFee/add";
    }

    /**
     * 添加停车费用记录到数据库
     * @param parkingFeeInfo
     * @return
     */
    @PostMapping("/addParkingFee")
    @ResponseBody
    @ApiOperation("添加停车费用记录到数据库")
    @Log(type="添加停车费用记录到数据库")
    public ResultVo addParkingFeeToDb(ParkingFeeInfo parkingFeeInfo){
        int result = parkingFeeService.addParkingFee(parkingFeeInfo);
        if(result==1){
            return ResultVoUtil.success("添加成功");
        }
        return ResultVoUtil.error("添加失败");
    }

    /**
     * 跳转到编辑停车费用记录页面
     * @param id
     * @return
     */
    @GetMapping("/editParkingFee/{id}")
    @ApiOperation("跳转到编辑停车费用记录页面")
    @Log(type="跳转到编辑停车费用记录页面")
    public String editParkingFee(@PathVariable("id") int id,ModelMap modelMap){
        modelMap.put("parkingFee",parkingFeeService.getParkingFee(id));
        return "admin/parkingFee/edit";
    }

    /**
     * 添加停车费用记录到数据库
     * @param parkingFeeInfo
     * @return
     */
    @PostMapping("/editParkingFee")
    @ResponseBody
    @ApiOperation("添加停车费用记录到数据库")
    @Log(type="添加停车费用记录到数据库")
    public ResultVo saveParkingFee(ParkingFeeInfo parkingFeeInfo){
        int result = parkingFeeService.editParkingFee(parkingFeeInfo);
        if(result==1){
            return ResultVoUtil.success("更新成功");
        }
        return ResultVoUtil.error("更新失败");
    }
    /**
     * 跳转到详细停车费用记录页面
     * @param id
     * @return
     */
    @GetMapping("/detailParkingFee/{id}")
    @ApiOperation("跳转到详细停车费用记录页面")
    @Log(type="跳转到详细停车费用记录页面")
    public String detailParkingFee(@PathVariable("id") int id,ModelMap modelMap){
        modelMap.put("parkingFee",parkingFeeService.getParkingFee(id));
        return "admin/parkingFee/detail";
    }


    /**
     * 删除一条停车费用记录
     * @param id
     * @return
     */
    @GetMapping("/deleteParkingFee/{id}")
    @ResponseBody
    @ApiOperation("删除一条停车费用记录")
    @Log(type="删除一条停车费用记录")
    public ResultVo deleteParkingFee(@PathVariable("id") int id){
        int result = parkingFeeService.deleteParkingFee(id);
        if(result==1){
            return ResultVoUtil.success("删除成功");
        }
        return ResultVoUtil.error("删除失败");
    }

    /**
     * 删除多条停车费用记录
     * @param ids
     * @return
     */
    @PostMapping("/deleteMultipleParkingFee")
    @ResponseBody
    @ApiOperation("删除多条停车费用记录")
    @Log(type="删除多条停车费用记录")
    public ResultVo deleteMultipleParkingFee(@RequestParam(value = "ids") List<Integer> ids){
        int result = parkingFeeService.deleteMultipleParkingFee(ids);
        if(result== ids.size()){
            return ResultVoUtil.success("删除成功");
        }
        return ResultVoUtil.error("删除失败");
    }

    /**
     * 提醒用户缴纳停车费用
     * @return
     */
    @GetMapping("/remind")
    @ApiOperation("提醒用户缴纳停车费用")
    @ResponseBody
    @Log(type="提醒用户缴纳停车费用")
    public ResultVo remindPayParkingFee(){
        parkingFeeService.remindPayParkingFee();
        return ResultVoUtil.success("提醒成功");
    }
}
